package com.hspedu.homework.homework8;

import java.util.Date;

public class SavingsAccount extends BankAccount {
    private double profit;//利息
    private int months;//几个月
    private int cnt;//交易次数
    private int free;//免费次数

    public void earnMonthlyInterest() {
        for (int i = 1; i <= months ; i++) {
            super.deposit(profit);
            System.out.println("利息\t" + "+" + profit +  "\t余额\t" + getBalance());
            cnt++;
            if(cnt %3 == 0 ){
                free++;
            }
        }
    }

    //取款
    @Override
    public void deposit(double amount) {
        if(free > 0 &&(free--) !=0 ){
            System.out.println("本次存款免除手续费,剩余免除次数:"+free);
            super.deposit(amount);
        }else{
            super.deposit(amount-1);
        }

    }

    @Override
    public void withdraw(double amount) {
        if (free > 0 && (free--)!=0 ){
            System.out.println("本次取款免除手续费,剩余免除次数:"+free);
            super.withdraw(amount);
        }else{
            super.withdraw(amount+1);
        }
    }
    public SavingsAccount(double initialBalance, double profit, int months, int cnt) {
        super(initialBalance);
        this.profit = profit;
        this.months = months;
        setCnt(cnt);
    }

    public double getProfit() {
        return profit;
    }

    public void setProfit(double profit) {
        this.profit = profit;
    }

    public int getMonths() {
        return months;
    }

    public void setMonths(int months) {
        this.months = months;
    }

    public int getCnt() {
        return cnt;
    }

    public void setCnt(int cnt) {
        if (cnt < 0 ) {
            System.out.println("交易次数(cnt),需要>0");
            return;
        }
        this.cnt = cnt;
    }
}
